import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {
    public static void main(String[] args) {
        // 搜索字符串
        String s = "the quick brown fox jumps over the lazy dog.";
        Pattern p = Pattern.compile("\\wo\\w");
        Matcher m = p.matcher(s);
        while (m.find()) {
            String sub = s.substring(m.start(), m.end());
            System.out.println(sub);
        }
        // 替换字符串
        String s1 = "The     quick\t\t brown   fox  jumps   over the  lazy dog.";
        String r1 = s1.replaceAll("\\s+", " ");
        System.out.println(r1); // "The quick brown fox jumps over the lazy dog."
        // 反向引用
        String s3 = "the quick brown fox jumps over the lazy dog.";
        String r2 = s3.replaceAll("\\s([a-z]{4})\\s", " <b>$1</b> ");
        System.out.println(r2);
    }

}
